import Enity from "./Enity.js"
import { enemyBulletImg } from "../image.js";
//子弹类
class EnemyBullet extends Enity {
    type = 'bullet'
    name = "敌人子弹"
    img;//所使用的图片
    v = 5;//速度
    atk = 0.5//子弹的攻击力
    constructor(x, y, arkTarget = ['player']) {
        super(x, y, 8)
        this.img = enemyBulletImg
        this.atkTarget = arkTarget
    }
    //显示图片
    draw = function (ctx) {
        ctx.drawImage(this.img, this.x - this.R, this.y - this.R, this.R * 2, this.R * 2)
    }
    //行为
    behavior = function (context) {
        this.move(context)//移动
        context = this.hit(context)
        return context
    }
    //移动方式
    move = function () {
        this.y += this.v
    }
    //撞击判断
    hit = function (context) {
        let player = context.NodeList[1]
        if(this.nodeDistance(player)<=this.R + player.R- 5){
            if (player.hp) {
                player.hp -= this.atk
                //子弹销毁
                this.OK = false
            }
        }
        return context
    }
    //状态判断
    isOK(context) {
        if (this.y < -10 || this.y > 500) {
            this.OK = false
        }
        return context
    }
}
export default EnemyBullet